package org.example.smart.Client;


import com.briup.smart.env.client.Client;
import com.briup.smart.env.entity.Environment;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
//客户端网络模块：将采集到的数据发送给服务端
public class ClientImpl implements Client {
    @Override
    public void send(Collection<Environment> collection){
        String ip = "127.0.0.1";
        int port = 8030;
        try(Socket socket = new Socket(ip,port);
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());){
            System.out.println("连接服务端成功！");
            GatherImpl gather = new GatherImpl();
            System.out.println("准备发送数据");
            oos.writeObject(collection);
            System.out.println("发送数据成功共" +collection.size() + "条！");
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("客户端网络模块成功关闭");
    }
}
